#
# 感恩日记和挑战认知模块
#


import _thread
import datetime
import json

import redis
from rasa_sdk.executor import CollectingDispatcher
from typing import Text, Dict, Any, List

from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, SessionStarted, UserUtteranceReverted
from actions import common
import requests
import re
import time
import random


def current_thought(tracker):
    num = tracker.get_slot('thought_3_change_1')
    cur = 'thought_' + str(num)
    text = tracker.get_slot(cur)
    return text


def save_diary(dispatcher, tracker, text):
    userid = tracker.current_state()['sender_id']
    conn = common.POOL.connection(shareable=False)
    cursor = conn.cursor()
    value = tracker.get_slot(text)
    try:
        x = common.getallmysql(
            "select * from user_info where id='" + userid + "'")
        if value is not None:
            nickname = x[0][1]
            names = x[0][2]
            if nickname is None:
                nickname = ''
            if names is None:
                names = ''
            sql = "insert into `user_diary`(`id`,`user_info_id`,`gratitude_diary`,`create_time`,`nick_name`,`test_batch`,`name`) values('" + common.getuid() + "','" + userid + "','" + value + "',now(),'" + nickname + "'," + str(
                x[0][35]) + ",'"+names+"');"
            common.connectmysql(sql)
    except:
        dispatcher.utter_message(text='save_error')
    finally:
        cursor.close()
        conn.close()
    return []


def conversation_rounds(tracker, **type):
    try:
        if common.rediscommon().get(tracker.current_state()['sender_id'] + '-wx-block-module2'):
            r = common.rediscommon()
            userid = tracker.current_state()['sender_id']
            r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
            common.rediscommon().delete(tracker.current_state()['sender_id'] + '-wx-block-module2')
            return []
    except:
        pass
    if 'type' in type:
        if type['type'] == 1:
            userid = tracker.current_state()['sender_id']
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            cursor.execute(
                "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
            x = cursor.fetchone()
            sql = "update `user_result` set conversation_rounds=" + str(x[
                                                                            15] + 1) + ",is_part_know=1 where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
            return []
    userid = tracker.current_state()['sender_id']
    conn = common.POOL.connection(shareable=False)
    cursor = conn.cursor()
    cursor.execute(
        "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
    x = cursor.fetchone()
    if x[18] not in [(), None, ]:
        r = common.rediscommon()
        try:
            temp = float(r.get(userid + 'TempTimeSteame'))
        except:
            temp = 0
        timenow = time.time()
        c = round(timenow - temp, 3)
        if x[18] == 0.001:
            sql = "update `user_result` set conversation_rounds=" + str(x[15] + 1) + ",response_time=" + str(
                c) + " where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
        else:
            sql = "update `user_result` set conversation_rounds=" + str(x[15] + 1) + ",response_time=" + str(x[
                                                                                                                 18] + c) + " where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
        r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
    else:
        r = common.rediscommon()
        r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
        sql = "update `user_result` set conversation_rounds=" + str(x[
                                                                        15] + 1) + ",response_time=0.000 where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
        common.connectmysql(sql)
    return []


class next(Action):
    def name(self) -> Text:
        return "action_next"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="此功能开发中，敬请期待！")
        return [SessionStarted()]


class how_you_feel(Action):
    def name(self) -> Text:
        return "action_how_you_feel"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_info` where `id` = '" + userid + "';")
            x = cursor.fetchone()
            wxid = x[16]
            _thread.start_new_thread(common.flashname, (wxid, dispatcher, userid))
            nickname = x[1]
            names = x[2]
            if nickname is None:
                nickname = ''
            if names is None:
                names = ''
            sql = "insert into `user_result`(`id`,`user_info_id`,`topic_type`,`name`,`conversation_rounds`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "',3,'" + names + "',0,'" + nickname + "'," + str(
                x[35]) + ");"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message('机器人错误 错误码0x103')
        finally:
            cursor.close()
            conn.close()
        if common.rediscommon().get(userid + 'first_login_rasa'):
            common.rediscommon().delete(userid + 'first_login_rasa')
            sqlup = "update user_info set user_frist_login = 1 where id='" + userid + "'"
            common.connectmysql(sqlup)
        dispatcher.utter_message(text="你现在感觉怎么样？", buttons=[
            {"payload": "/feel_good", "title": "挺好的呀", "life": 1},
            {"payload": "/feel_bad", "title": "不太好", "life": 1},
        ], json_message={"module_type": 2})
        conversation_rounds(tracker)
        return []


class how_you_feel_good(Action):
    def name(self) -> Text:
        return "action_how_you_feel_good"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="具体说说呢？", buttons=[
            {"payload": "/really_happy", "title": "很开心😄", "life": 1},
            {"payload": "/happy", "title": "开心😊", "life": 1},
            {"payload": "/content", "title": "满足😌", "life": 1},
            {"payload": "/okey", "title": "就还行😐", "life": 1},
        ])
        return []


class how_you_feel_bad(Action):
    def name(self) -> Text:
        return "action_how_you_feel_bad"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="你现在感觉心情怎么样？", buttons=[
            {"payload": "/sad", "title": "悲伤🙁", "life": 1},
            {"payload": "/depressed", "title": "郁闷😔", "life": 1},
            {"payload": "/anxious", "title": "焦虑😰", "life": 1},
            {"payload": "/angry", "title": "生气😠", "life": 1},
            {"payload": "/sick", "title": "不舒服🤒", "life": 1},
            {"payload": "/tired", "title": "疲惫🥱", "life": 1},
        ])
        return []


class sick_1_1(Action):
    def name(self) -> Text:
        return "action_sick_1_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="很高兴知道你过得很好。我自己也感觉有点儿迟钝，大概是天气的原因吧。", buttons=[
            {"payload": "/button_sick_1_2", "title": "嗯嗯", "life": 1},
        ])
        return []


class sick_1_2(Action):
    def name(self) -> Text:
        return "action_sick_1_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="那让我们做一些感恩日记来结束今天吧。", buttons=[
            {"payload": "/button_sick_1_3", "title": "好呀", "life": 1},
            {"payload": "/gratitude_journal_where_notin_yes", "title": "我今天不想继续了", "life": 1}
        ])
        return []


class sick_1_3(Action):
    def name(self) -> Text:
        return "action_sick_1_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="在我们开始之前，你应该知道——你可以通过选择底部的“日记”来找到你过去所有的感恩日记", buttons=[
            {"payload": "/into_grateful_thing_input_1", "title": "好的", "life": 1},
        ])
        return []


class content_1_1(Action):
    def name(self) -> Text:
        return "action_content_1_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="那可太棒啦！~一直保持下去吧！", buttons=[
            {"payload": "/happy_1_yes", "title": "我会的", "life": 1},
            {"payload": "/happy_1_yes", "title": "嘿嘿", "life": 1},
        ])
        return []


class sorry_to_hear(Action):
    def name(self) -> Text:
        return "action_sorry_to_hear"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="天啦噜，这可真是太难受啦", buttons=[
            {"payload": "/sorry_to_hear_yes", "title": "是呢", "life": 1},
        ])
        return []


class deal_or_share(Action):
    def name(self) -> Text:
        return "action_deal_or_share"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="你想要跟我一起来解决这个情况吗？还是只想要一吐为快？？", buttons=[
            {"payload": "/want_help", "title": "我想要得到一些帮助", "life": 1},
            {"payload": "/want_share", "title": "只是想要分享一下", "life": 1},
        ])
        return []


class take_10min(Action):
    def name(self) -> Text:
        return "action_take_10min"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="太好啦，能帮助你一起思考这个问题我可太高兴啦，")
        dispatcher.utter_message(text="我有一些很棒的工具可以帮助人们感觉更好哦。不过大概要花10分钟左右的时间，可以吗?", buttons=[
            {"payload": "/take_10min_yes", "title": "好的", "life": 1},
            {"payload": "/take_10min_no", "title": "现在不方便", "life": 1},
        ])
        return []


class into_gratitude_journaling(Action):
    def name(self) -> Text:
        return "action_into_gratitude_journaling"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="没问题")
        dispatcher.utter_message(text="我们尝试换个角度，试着写一些感恩日记吧？", buttons=[
            {"payload": "/into_gratitude_journaling_yes", "title": "哎？好呀~听上去挺好玩的", "life": 1},
            # {"payload": "/want_share", "title": "只是想要分享一下"},
        ])
        return []


class tell_more_feeling(Action):
    def name(self) -> Text:
        return "action_tell_more_feeling"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="多告诉我一些你的感受吧")
        return []


class gratitude_journal_where(Action):
    def name(self) -> Text:
        return "action_gratitude_journal_where"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="在我们开始之前，我要说明一下——")
        dispatcher.utter_message(text="你可以通过选择顶部的\"日记 \"来找到你过去所有的感恩日记条目哦。", buttons=[
            {"payload": "/gratitude_journal_where_yes", "title": "好的", "life": 1},
            # {"payload": "/want_share", "title": "只是想要分享一下"},
        ])
        return []


class greatful_different_things(Action):
    def name(self) -> Text:
        return "action_greatful_different_things"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute("Select * from `user_info` where `id` = '" + userid + "';")
            x = cursor.fetchone()
            name = x[2]
            if name == None:
                name = x[1]
            dispatcher.utter_message(text="首先，" + name + ", 你会对很多不同的事情心存感激", buttons=[
                {"payload": "/greatful_different_things_yes", "title": "嗯……🤔比如说呢？", "life": 1},
                {"payload": "/into_grateful_thing_input_1", "title": "我已经想到一个要写的了", "life": 1},
            ])
        except:
            print("greatful_different_things error")
        return []


class greatful_thing_example(Action):
    def name(self) -> Text:
        return "action_greatful_thing_example"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="就像你生命中出现的人，你拥有的回忆和今天发生的美好的事情\n")
        dispatcher.utter_message(text="甚至你喜欢的东西，比如你最喜欢的吉他或者自行车", buttons=[
            {"payload": "/greatful_thing_example_yes", "title": "对你来说呢？", "life": 1},
            {"payload": "/into_grateful_thing_input_1", "title": "我懂了", "life": 1},
        ])
        return []


class grateful_pet(Action):
    def name(self) -> Text:
        return "action_grateful_pet"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="对我而言，我常常对宠物心存感激\n")
        dispatcher.utter_message(text="他们和我一样忠诚、可爱，让你的每一天更美好~", buttons=[
            {"payload": "/grateful_pet_yes", "title": "哇哦~你可太厉害啦👍👍，我第一次见到你这么厉害的机器人呢", "life": 1},
            {"payload": "/into_grateful_thing_input_1", "title": "明白啦", "life": 1},
        ])
        return []


class grateful_not_everyone(Action):
    def name(self) -> Text:
        return "action_grateful_not_everyone"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="但并不是每个人都和我一样这么觉得\n")
        dispatcher.utter_message(text="我的邻居们并不喜欢我的宠物小青蛙在早晨唱rap")
        dispatcher.utter_message(text="他只是为自己被吵醒而烦躁……", buttons=[
            {"payload": "/grateful_not_everyone_yes", "title": "啥？？青蛙？？", "life": 1},
            {"payload": "/into_grateful_thing_input_1", "title": "嗯嗯~", "life": 1},
        ])
        return []


class grateful_adopt(Action):
    def name(self) -> Text:
        return "action_grateful_adopt"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="是呢，我在几个月前收养了一只小青蛙\n",
                                 image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/frog.png')
        dispatcher.utter_message(text="或者说他收养了我?……", buttons=[
            {"payload": "/grateful_adopt_yes", "title": "嗯嗯", "life": 1},
            {"payload": "/grateful_adopt_yes", "title": "好奇怪呀", "life": 1},
        ])
        return []


class grateful_feed(Action):
    def name(self) -> Text:
        return "action_grateful_feed"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="好吧，也许不是\"收养\"，但它前些日子在我的花园里定居了\n")
        dispatcher.utter_message(text="现在我每天给它喂食，带它去散步", buttons=[
            {"payload": "/into_grateful_thing_input_1", "title": "啊，我明白了", "life": 1},
            {"payload": "/into_grateful_thing_input_1", "title": "更奇怪了好吗", "life": 1},
        ])
        return []


class action_ask_diary_1(Action):
    def name(self) -> Text:
        return "action_ask_diary_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        if 'event' in tracker.current_state()['events'][-7]:
            if tracker.current_state()['events'][-7]['event'] == 'session_started':
                conn = common.POOL.connection(shareable=False)
                cursor = conn.cursor()
                try:
                    cursor.execute(
                        "Select * from `user_info` where `id` = '" + userid + "';")
                    x = cursor.fetchone()
                    nickname = x[1]
                    names = x[2]
                    if nickname is None:
                        nickname = ''
                    if names is None:
                        names = ''
                    test_batch=  str(x[35])
                    sql = "insert into `user_result`(`id`,`user_info_id`,`topic_type`,`name`,`conversation_rounds`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "',3,'" + names + "',0,'" + nickname + "'," + str(
                        x[35]) + ");"
                    common.connectmysql(sql)
                    cursor.close()
                    conn.close()
                    conn = common.POOL.connection(shareable=False)
                    cursor = conn.cursor()
                    cursor.execute(
                        "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
                    x = cursor.fetchone()
                    sql = "insert into `user_tools_response` (`id`,`user_info_id`,`user_result_id`,`name`,`use_tools`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "','" + \
                          x[0] + "','" + names + "','感恩日记','" + nickname + "'," + test_batch + ");"
                    common.connectmysql(sql)
                except:
                    dispatcher.utter_message(text='机器人错误 错误码0x006')
                    return [UserUtteranceReverted()]
                finally:
                    cursor.close()
                    conn.close()
        conversation_rounds(tracker)
        dispatcher.utter_message(text='那么告诉我，你今天最感激的事情是什么？在下方输入你的答案，不要点击任何选项哦', json_message={"word_module_type": 2})
        return []


class action_ask_diary_2(Action):
    def name(self) -> Text:
        return "action_ask_diary_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='太棒了'),
        dispatcher.utter_message(text='还有其他觉得感恩的事情吗？'),
        dispatcher.utter_message(text='是件大惊喜还是小确幸？在下面写下来吧~'),
        text = 'diary_1'
        save_diary(dispatcher, tracker, text)
        return []


class action_ask_diary_3(Action):
    def name(self) -> Text:
        return "action_ask_diary_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='再来尝试最后一次~'),
        dispatcher.utter_message(text='在你的生活中，你有什么值得感激的事情？'),
        text = 'diary_2'
        save_diary(dispatcher, tracker, text)
        return []


class good_job(Action):
    def name(self) -> Text:
        return "action_good_job"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = 'diary_3'
        save_diary(dispatcher, tracker, text)
        try:
            i = random.randint(1, 3)
            url = 'https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/highfive/highfive_' + str(
                i) + '.jpg'
            dispatcher.utter_message(text='yeah~干得漂亮！', image=url, buttons=[
                {"payload": "/good_job_yes", "title": "鼓掌鼓掌！", "life": 1},
                {"payload": "/good_job_yes", "title": "谢谢夸奖~我就是这么棒~", "life": 1},
            ])
            a = []
            a.append(SlotSet("diary_1", None))
            a.append(SlotSet("diary_2", None))
            a.append(SlotSet("diary_3", None))
            return a
        except:
            dispatcher.utter_message(text='yeah~干得漂亮！！！！', buttons=[
                {"payload": "/good_job_yes", "title": "鼓掌鼓掌！", "life": 1},
                {"payload": "/good_job_yes", "title": "谢谢夸奖~我就是这么棒~", "life": 1},
            ])
            a = []
            a.append(SlotSet("diary_1", None))
            a.append(SlotSet("diary_2", None))
            a.append(SlotSet("diary_3", None))
            return a


class diary_longterm(Action):
    def name(self) -> Text:
        return "action_diary_longterm"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="这就是我所说的感恩日记。怎么样？还不错吧~")
        dispatcher.utter_message(text="接下来，我们将在整个对话过程中一起来做", buttons=[
            {"payload": "/diary_longterm_yes", "title": "好呀", "life": 1},
        ])
        return []


class interesting_require(Action):
    def name(self) -> Text:
        return "action_interesting_require"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="你对这节课感兴趣吗？", buttons=[
            {"payload": "/interesting_require_yes", "title": "很棒！", "life": 1},
            {"payload": "/interesting_require_no", "title": "不行", "life": 1},
        ])
        # dispatcher.utter_message(text="你对这节课感兴趣吗？")
        return []


class share_opinion(Action):
    def name(self) -> Text:
        return "action_share_opinion"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            if tracker.current_state()['events'][-2]['text'] == '/interesting_require_yes':
                sql = "update user_tools_response set evaluation_diary='很棒！' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            if tracker.current_state()['events'][-2]['text'] == '/interesting_require_no':
                sql = "update user_tools_response set evaluation_diary='不行' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x050')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text="谢谢~我会把你的意见跟我的人类伙伴分享的~", buttons=[
            {"payload": "/share_opinion_yes", "title": "好的", "life": 1},
        ])
        return []


class good_gratitude_write(Action):
    def name(self) -> Text:
        return "action_good_gratitude_write"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="你今天的感恩日记写得非常好，Good job！"),
        dispatcher.utter_message(text="我对我们以后一起的生活充满了期待~", buttons=[
            {"payload": "/good_gratitude_write_yes", "title": "好的", "life": 1},
        ])
        return []


# ————————————————————————————————————————感恩日记————————————————————————————————————————————————


class research_idea(Action):
    def name(self) -> Text:
        return "action_research_idea"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="当你情绪低落时，了解你的想法如何影响你的情绪有意想不到的帮助哦~\n")
        dispatcher.utter_message(text="所以，我们来仔细研究一下你的想法，摆脱坏情绪吧~", buttons=[
            {"payload": "/research_idea_yes", "title": "好呀", "life": 1},
        ])
        return []


class circle_back(Action):
    def name(self) -> Text:
        return "action_circle_back"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="好的，我们总是可以再次回到这里哦\n")
        dispatcher.utter_message(text="让我们做一些感恩日记来总结我们的第一天吧~", buttons=[
            {"payload": "/circle_back_yes", "title": "好呀", "life": 1},
            {"payload": "/circle_back_no", "title": "不要", "life": 1},
        ])
        return []


class gratitude_journal_where_notin(Action):
    def name(self) -> Text:
        return "action_gratitude_journal_where_notin"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="当你想要使用感恩日记时，点击屏幕底部的日记，就可以看到你所有的感恩日记啦！", buttons=[
            {"payload": "/gratitude_journal_where_notin_yes", "title": "好呀", "life": 1},
            {"payload": "/gratitude_journal_where_notin_yes", "title": "嗯嗯，知道啦", "life": 1},
        ])
        return []


class dialog_end(Action):
    def name(self) -> Text:
        return "action_dialog_end"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text="聊天的时间总是过得这么快。")
        dispatcher.utter_message(text="很高兴今天见到你~希望我们今后能一起进步，每天开心~")
        dispatcher.utter_message(text='你已完成当天的实验流程')
        dispatcher.utter_message(text="明天再聊，再见啦👋~", buttons=[{"payload": "/greet", "title": "返回首页"}, ])
        return [SessionStarted()]


# -----------------------------------------------part 1-----------------------------------------------------


class part2_1_choose(Action):
    def name(self) -> Text:
        return "action_part2_1_choose"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute(
            "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
        x = cursor.fetchone()
        if x[16]:
            dispatcher.utter_message(text="好的，首先选择一个你最强烈地感受到所有这些困难的特定时刻。是现在，还是过去的某个时候呢？", buttons=[
                {"payload": "/button_part2_1_choose_1", "title": "现在", "life": 1},
                {"payload": "/button_ask_past_moment", "title": "过去的某个时间", "life": 1},
            ])
        else:
            dispatcher.utter_message(text="好的，首先选择一个你最强烈地感受到所有这些困难的特定时刻。是现在，还是过去的某个时候呢？", buttons=[
                {"payload": "/button_part2_1_choose_1", "title": "现在", "life": 1},
                {"payload": "/button_ask_past_moment", "title": "过去的某个时间", "life": 1},
                {"payload": "/button_part2_1_choose_3", "title": "为什么要这样做？", "life": 1}
            ])
        cursor.close()
        conn.close()
        return []


class part2_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part2_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        if 'text' in tracker.current_state()['events'][-2]:
            if tracker.current_state()['events'][-2]['text'] == '/button_part2_1_choose_1':
                conn = common.POOL.connection(shareable=False)
                cursor = conn.cursor()
                try:
                    cursor.execute(
                        "Select * from `user_info` where `id` = '" + userid + "';")
                    x = cursor.fetchone()
                    nickname = x[1]
                    names = x[2]
                    if nickname is None:
                        nickname = ''
                    if names is None:
                        names = ''
                    test_batch=  str(x[35])
                    sql = "insert into `user_result`(`id`,`user_info_id`,`topic_type`,`name`,`conversation_rounds`) values('" + common.getuid() + "','" + userid + "',3,'" + names + "',0,'" + nickname + "'," + str(
                        x[35]) + ");"
                    common.connectmysql(sql)
                    cursor.close()
                    conn.close()
                    conn = common.POOL.connection(shareable=False)
                    cursor = conn.cursor()
                    cursor.execute(
                        "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
                    x = cursor.fetchone()
                    sql = "insert into `user_tools_response` (`id`,`user_info_id`,`user_result_id`,`name`,`use_tools`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "','" + \
                          x[0] + "','" + names + "','挑战认知','" + nickname + "'," + test_batch + ");"
                    common.connectmysql(sql)
                except:
                    dispatcher.utter_message(text='机器人错误 错误码0x006')
                    return [UserUtteranceReverted()]
                finally:
                    cursor.close()
                    conn.close()
        conversation_rounds(tracker)
        if tracker.get_slot('past_moment'):
            sql = "update `user_result` set idea='" + tracker.get_slot(
                'past_moment') + "=@=' where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1"
            common.connectmysql(sql)
        dispatcher.utter_message(text="好的，在这一刻进入你消极的自动想法.")
        dispatcher.utter_message(text="想象一下,如果你的负面情绪有声音会说什么呢……你能做到吗？", buttons=[
            {"payload": "/button_into_thought", "title": "我可以做到", "life": 1},
            {"payload": "/button_part2_1_2_choose_2", "title": "想象不到……", "life": 1},
            {"payload": "/button_part2_1_2_choose_3", "title": "可以举个例子吗？", "life": 1}
        ], json_message={"word_module_type": 3})
        return []


class part2_1_2_choose_2(Action):
    def name(self) -> Text:
        return "action_part2_1_2_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="当你感觉到这些强烈的负面情绪时，试着找出一个突然出现在你脑中的可引用的短语")
        dispatcher.utter_message(text='''这些短语通常是第一人称（涉及 "我"、"我的 "等）''')
        dispatcher.utter_message(text='''......但尽量避免"我觉得...... "的说法，因为感觉比思想更难挑战''', buttons=[
            {"payload": "/button_into_thought", "title": "有一个", "life": 1},
            {"payload": "/button_part2_1_2_choose_3", "title": "可以随便举个例子吗？", "life": 1}
        ])
        return []


class part2_1_2_choose_3(Action):
    def name(self) -> Text:
        return "action_part2_1_2_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="一些常见的想法是：我是一个失败者")
        dispatcher.utter_message(text="我不能再忍受了")
        dispatcher.utter_message(text="有些事永远无法改变")
        dispatcher.utter_message(text="你可以把这个想法写出来吗？", buttons=[
            {"payload": "/button_into_thought", "title": "知道了", "life": 1},
            {"payload": "/button_into_thought", "title": "我试试", "life": 1},
        ])
        return []


class action_ask_past_moment(Action):
    def name(self) -> Text:
        return "action_ask_past_moment"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='想一想是在过去哪一个具体的时间点呢？'),
        dispatcher.utter_message(text='你那会儿在哪里?和谁在一起?在做什么?然后写在这里'),
        dispatcher.utter_message(text='请输入文字让小E更懂你，不要点击选项')
        return []


# ----------------------------三个想法---------------------------
class action_ask_thought_1(Action):
    def name(self) -> Text:
        return "action_ask_thought_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='好的，在这里简短地写下其中一个消极想法吧~✏️'),
        return []


class action_ask_thought_2(Action):
    def name(self) -> Text:
        return "action_ask_thought_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_info` where `id` = '" + userid + "';")
            x = cursor.fetchone()
            nickname = x[1]
            names = x[2]
            if nickname is None:
                nickname = ''
            if names is None:
                names = ''
            test_batch = str(x[35])
            cursor.close()
            conn.close()
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            sql = "insert into `user_heart` (`id`,`user_info_id`,`user_result_id`,`name`,`thought_one`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "','" + \
                  x[0] + "','" + names + "','" + tracker.get_slot('thought_1') + "','" + nickname + "'," + test_batch + ");"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x006')
            return [UserUtteranceReverted()]
        dispatcher.utter_message(text='......再写一个（记得简短一些哦）✏️'),
        return []


class action_ask_thought_3(Action):
    def name(self) -> Text:
        return "action_ask_thought_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            sql = "update `user_heart` set `thought_two`='" + tracker.get_slot(
                'thought_2') + "' where user_info_id ='" + userid + "' and user_result_id='" + x[0] + "'"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x006')
            return [UserUtteranceReverted()]
        dispatcher.utter_message(text='再来写最后一个吧~✏️'),
        return []


class action_choose_thought(Action):
    def name(self) -> Text:
        return "action_choose_thought"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        # if tracker.get_slot('past_moment'):
        #     sql = "update `user_result` set idea='"+tracker.get_slot('past_moment')+ "=@=" + tracker.get_slot('thought_1') + "=@="+tracker.get_slot('thought_2')+"=@="+tracker.get_slot('thought_3')+"' where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1"
        #     common.connectmysql(sql)
        # else:
        #     sql = "update `user_result` set idea='" + tracker.get_slot('thought_1') + "=@=" + tracker.get_slot(
        #         'thought_2') + "=@=" + tracker.get_slot(
        #         'thought_3') + "' where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1"
        #     common.connectmysql(sql)
        if tracker.get_slot('past_moment'):
            sql = "update `user_result` set past_moment='" + tracker.get_slot(
                'past_moment') + "' where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1"
            common.connectmysql(sql)
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            sql = "update `user_heart` set `thought_three`='" + tracker.get_slot(
                'thought_3') + "' where user_info_id ='" + userid + "' and user_result_id='" + x[0] + "'"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x006')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()

        conversation_rounds(tracker)
        dispatcher.utter_message(text='这些都是我们可以一起挑战的想法你想要先从哪个开始？', buttons=[
            {"payload": "/button_part3_1_1_choose_1_thought_1", "title": tracker.get_slot('thought_1'), "life": 1,
             "nanoha": 1},
            {"payload": "/button_part3_1_1_choose_1_thought_2", "title": tracker.get_slot('thought_2'), "life": 1,
             "nanoha": 2},
            {"payload": "/button_part3_1_1_choose_1_thought_3", "title": tracker.get_slot('thought_3'), "life": 1,
             "nanoha": 3}
        ]),
        return []


# ——————————————————————————————————————————————————————————————————————

class part2_1_choose_3(Action):
    def name(self) -> Text:
        return "action_part2_1_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker, type=1)
        dispatcher.utter_message(text="好问题，如果你想听的话，我可以讲个故事吗？听了故事你就明白了", buttons=[
            {"payload": "/button_part2_3_2_choose_1", "title": "当然可以", "life": 1},
            {"payload": "/button_part2_1_choose_1", "title": "不，谢谢", "life": 1},
        ])
        return []


class part2_3_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part2_3_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="我有个朋友德华最近情绪很低落，他刚刚经历了分手，而且一直走不出来", buttons=[
            {"payload": "/button_part2_3_3_choose_1", "title": "哦", "life": 1}
        ])
        return []


class part2_3_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part2_3_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="我打电话安慰他时，他把他们在一起时的每一个细节都说了一遍")
        dispatcher.utter_message(text="有时，他还会翻看他们一起度假的旧照片……", buttons=[
            {"payload": "/button_part2_3_4_choose_1", "title": "这样啊", "life": 1}
        ])
        return []


class part2_3_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part2_3_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="可以理解的是，这让他对整件事感到更加难过😣", buttons=[
            {"payload": "/button_part2_3_5_choose_1", "title": "同感", "life": 1},
            {"payload": "/button_part2_3_5_choose_1", "title": "好可怜啊……", "life": 1}
        ])
        return []


class part2_3_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part2_3_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="我想帮他从情殇中走出来")
        dispatcher.utter_message(text="所以我请他举例说明他对前女友的感受", buttons=[
            {"payload": "/button_part2_3_6_choose_1", "title": "他说了什么？？", "life": 1}
        ])
        return []


class part2_3_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part2_3_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="他继续说他感到悲伤、愤怒和沮丧……")
        dispatcher.utter_message(text="……直到我让他记住一个，他特别强烈地感受到这些情绪的时刻", buttons=[
            {"payload": "/button_part2_3_7_choose_1", "title": "嗯……有意思🤔", "life": 1},
            {"payload": "/button_part2_3_7_choose_2", "title": "你为什么对他说这些？", "life": 1}
        ])
        return []


class ppart2_3_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part2_3_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="然后，因为他当时正专注于某一段记忆，我就问他那个时刻脑海中在想什么", buttons=[
            {"payload": "/button_part2_3_8_choose_1", "title": "脑海里面有什么？", "life": 1}
        ])
        return []


class part2_3_7_choose_2(Action):
    def name(self) -> Text:
        return "action_part2_3_7_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="是这样的，如果他只专注于一段特定的记忆，他会更容易抓住那一刻在他脑海中浮现的想法", buttons=[
            {"payload": "/button_part2_3_8_choose_1", "title": "那他在想什么呢？", "life": 1}
        ])
        return []


class part2_3_8_choose_1(Action):
    def name(self) -> Text:
        return "action_part2_3_8_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="他想“我再也找不到这么特别的人了”，还有“没有人会爱我”", buttons=[
            {"payload": "/button_part3_1_choose_1", "title": '''啊……''', "life": 1},
            {"payload": "/button_part3_1_choose_1", "title": '''你是怎么回应的''', "life": 1}
        ])
        return []


# ----------------------------------------------------part2----------------------------------------
class part3_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="这些都是一些感到痛苦的想法所以我试着帮他重新定义：")
        dispatcher.utter_message(text="他感到受伤是因为他觉得被他所深爱的人拒绝了，这很正常。")
        dispatcher.utter_message(text="但是像“没有人会爱我”这样的想法是属于认知扭曲的，是我们可以通过努力改变的想法💪", buttons=[
            {"payload": "/button_part3_2_choose_1", "title": '''我明白了''', "life": 1},
            {"payload": "/button_part3_2_choose_2", "title": '''认知扭曲？？''', "life": 1},
        ])
        return []


class part3_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="我非常理解他想要找到灵魂的另一半，感受到被宠爱的欲望--这是正常的人类的欲望。")
        dispatcher.utter_message(text="当他认识到这种被爱的欲望是他悲伤的根本理由时，他意识到了一些事情......", buttons=[
            {"payload": "/button_part3_3_choose_1", "title": '''是什么？''', "life": 1},
        ])
        return []


class part3_2_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_2_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="它们是感觉100%正确的思维错误，这可能会导致一些糟糕的情绪")
        dispatcher.utter_message(text="我们今天来一起识别并解决你可能出现的认知扭曲吧", buttons=[
            {"payload": "/button_part3_2_choose_1", "title": '''好呀''', "life": 1}
        ])
        return []


class part3_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="他说我是对的，实际上这次分手让他认识到了关于他自己的一些事。")
        dispatcher.utter_message(text="他不是不值得被爱，而是太过于钟情--这才是为什么他觉得如此受伤", buttons=[
            {"payload": "/button_part3_4_choose_1", "title": '''是啊……''', "life": 1}
        ])
        return []


class part3_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="他说我是对的，实际上这次分手让他认识到了关于他自己的一些事。")
        dispatcher.utter_message(text="他不是不值得被爱，而是太过于钟情--这才是为什么他觉得如此受伤", buttons=[
            {"payload": "/button_part3_5_choose_1", "title": '''嗯嗯''', "life": 1},
            {"payload": "/button_part3_5_choose_2", "title": '''悖论？是什么意思？''', "life": 1}
        ])
        return []


class part3_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="矛盾的是，一旦他发现他最黑暗的时刻其实也表现了他引以为豪的特征，那么就可以稍微地消解那一刻的感受", buttons=[
            {"payload": "/button_part3_6_choose_1", "title": '''怎么说？''', "life": 1},
            {"payload": "/button_part3_6_choose_2", "title": '''有道理''', "life": 1}
        ])
        return []


class part3_5_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_5_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="悖论是一种自相矛盾的想法，但仍有一定的意义。")
        dispatcher.utter_message(text="例如，如果你正在为比赛进行训练，在一周中的某些日子里跑得慢，实际上有助于你在关键时刻跑得更快。", buttons=[
            {"payload": "/button_part3_5_choose_1", "title": '''德华的悖论是什么呢？''', "life": 1},
            {"payload": "/button_part3_6_choose_2", "title": '''我明白了''', "life": 1}
        ])
        return []


class part3_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="通过识别和消除他思维中的认知扭曲。")
        dispatcher.utter_message(text='''我喜欢称之为"重写剧本" ✍''', buttons=[
            {"payload": "/research_idea_yes", "title": '''哇哦~''', "life": 1},
        ])
        return []


class part3_6_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_6_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text="其实我们还可以讨论很多问题，但是现在他对情况有了进一步的认识，可以重新写一下联想到的情节剧本了")
        dispatcher.utter_message(text='''你明白了吗？''', buttons=[
            {"payload": "/button_part3_7_choose_1", "title": '''嗯嗯''', "life": 1},
            {"payload": "/button_part3_7_choose_2", "title": '''没太明白……''', "life": 1},
        ])
        return []


class part3_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='''好了，现在回到你的问题上''', buttons=[
            {"payload": "/research_idea_yes", "title": '''好的''', "life": 1},
        ])
        return []


class part3_7_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_7_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='''别担心，hh！''')
        dispatcher.utter_message(text='''我们来一起练习一下，你就明白啦''', buttons=[
            {"payload": "/research_idea_yes", "title": '''好呀''', "life": 1},
        ])
        return []


# --------------------------------很开心 开心 还可以-----------------------------------------
class really_happy_1(Action):
    def name(self) -> Text:
        return "action_really_happy_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='''听到你说很开心可太棒啦~''')
        dispatcher.utter_message(text='''你开心我也开心~''', buttons=[
            {"payload": "/really_happy_1_yes", "title": '''开心的一天~''', "life": 1},
        ])
        return []


class really_happy_2(Action):
    def name(self) -> Text:
        return "action_really_happy_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='''听到你说很开心可太棒啦~''')
        dispatcher.utter_message(text='''你想现在就在你的感恩日记里记录下现在的美好吗?''', buttons=[
            {"payload": "/into_grateful_thing_input_1", "title": '''好呀~''', "life": 1},
            {"payload": "/into_end", "title": '''今天不想继续了''', "life": 1},
        ])
        return []


class happy_1(Action):
    def name(self) -> Text:
        return "action_happy_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='''很高兴听到你说今天很开心~''')
        dispatcher.utter_message(text='''一直保持下去吧！！''', buttons=[
            {"payload": "/happy_1_yes", "title": '''~嘿嘿~''', "life": 1},
            {"payload": "/happy_1_yes", "title": '''我争取''', "life": 1},
        ])
        return []


class happy_2(Action):
    def name(self) -> Text:
        return "action_happy_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='''让我们写一些感恩日记来总结我们第一天的工作吧~''', buttons=[
            {"payload": "/into_grateful_thing_input_1", "title": '''嗯呢！好呀~''', "life": 1},
            {"payload": "/into_end", "title": '''今天不想继续了''', "life": 1},
        ])
        return []


class ok_1(Action):
    def name(self) -> Text:
        return "action_ok_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='''很高兴听到你说还可以''')
        dispatcher.utter_message(text='''我觉得自己有点迟钝''')
        dispatcher.utter_message(text='''可能是天气的原因……''', buttons=[
            {"payload": "/ok_1_yes", "title": '''有可能''', "life": 1},
        ])
        return []


class ok_2(Action):
    def name(self) -> Text:
        return "action_ok_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='''沉浸在美好的感觉中总是很美好的️''')
        dispatcher.utter_message(text='''考虑到这一点，你想现在就在你的感恩日记里写下来吗?''', buttons=[
            {"payload": "/into_grateful_thing_input_1", "title": '''嗯呢！好呀~''', "life": 1},
            {"payload": "/into_end", "title": '''今天不想继续了''', "life": 1},
        ])
        return []


# ---------------------------------------------------------------------------------part3----------------------------------------------------
class part3_1_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='好的，你认为这个想法中有出现认知扭曲吗？',
                                 buttons=[{'payload': '/button_part3_1_2_choose_1', 'title': '认知扭曲？', 'life': 1},
                                          {'payload': '/button_part3_1_2_choose_2', 'title': '有出现', 'life': 1},
                                          {'payload': '/button_part3_1_2_choose_3', 'title': '没出现', 'life': 1},
                                          {'payload': '/button_part3_1_2_choose_3', 'title': '不确定', 'life': 1}, ])
        # if tracker.current_state()['events'][-2]['text']=='/button_part3_1_1_choose_1_thought_1':
        #     return [SlotSet('thought_3_change_1',tracker.get_slot('thought_1'))]
        # if tracker.current_state()['events'][-2]['text']=='/button_part3_1_1_choose_1_thought_2':
        #     return [SlotSet('thought_3_change_1',tracker.get_slot('thought_2'))]
        # if tracker.current_state()['events'][-2]['text']=='/button_part3_1_1_choose_1_thought_3':
        #     return [SlotSet('thought_3_change_1',tracker.get_slot('thought_3'))]
        if tracker.current_state()['events'][-2]['text'] == '/button_part3_1_1_choose_1_thought_1':
            return [SlotSet('thought_3_change_1', '1')]
        if tracker.current_state()['events'][-2]['text'] == '/button_part3_1_1_choose_1_thought_2':
            return [SlotSet('thought_3_change_1', '2')]
        if tracker.current_state()['events'][-2]['text'] == '/button_part3_1_1_choose_1_thought_3':
            return [SlotSet('thought_3_change_1', '3')]


class part3_1_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='认知扭曲是我们对自己玩的无用的心理把戏')
        dispatcher.utter_message(text='它们是感觉 100% 正确的思维错误，这可能会导致一些糟糕的情绪',
                                 buttons=[{'payload': '/button_part3_1_3_choose_1', 'title': '明白了', 'life': 1}, ])
        return []


class part3_1_2_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_2_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='认知扭曲是我们对自己玩的无用的心理把戏')
        dispatcher.utter_message(text='它们是感觉 100% 正确的思维错误，这可能会导致一些糟糕的情绪',
                                 buttons=[{'payload': '/button_part3_1_3_choose_1', 'title': '嗯嗯', 'life': 1}, ])
        return []


class part3_1_2_choose_3(Action):
    def name(self) -> Text:
        return "action_part3_1_2_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='让我们来仔细看看，以确保真的不存在认知扭曲吧',
                                 buttons=[{'payload': '/button_part3_1_4_choose_1', 'title': '好的', 'life': 1}, ])
        return []


class part3_1_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='学会识别这些扭曲是让自己感觉更好的第一步')
        dispatcher.utter_message(text='让我们看看我们是否能识别出这个想法中的认知扭曲',
                                 buttons=[{'payload': '/button_part3_1_4_choose_1', 'title': '好的', 'life': 1}, ])
        return []


class part3_1_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='来看看你刚刚输入的想法：' + text)
        dispatcher.utter_message(text='它是否假设你的生活中存在永无止境的消极或失败模式？',
                                 buttons=[{'payload': '/button_part3_1_5_choose_1', 'title': '是的', 'life': 1},
                                          {'payload': '/button_part3_1_5_choose_2', 'title': '我觉得没有', 'life': 1},
                                          {'payload': '/button_part3_1_5_choose_3', 'title': '嗯……不太确定', 'life': 1}, ])
        return []


class part3_1_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='嗯嗯,这里谈到的扭曲称为“过度概括”,它通常与诸如“总是”和“从不”之类的词相关联',
                                 buttons=[{'payload': '/button_part3_1_6_choose_1', 'title': '我明白了', 'life': 1}, ])
        return []


class part3_1_5_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_5_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='知道了,以防它在以后突然出现，我来解释一下，这种扭曲被称为“过度概括”,它通常与诸如“总是”和“从不”之类的词相关联哦',
                                 buttons=[{'payload': '/button_part3_1_6_choose_2', 'title': '我明白了……', 'life': 1}, ])
        return []


class part3_1_5_choose_3(Action):
    def name(self) -> Text:
        return "action_part3_1_5_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='没关系，这就是我可以帮忙的地方呀~我在这里谈论的失真被称为“过度概括”，它通常与诸如“总是”和“从不”之类的词相关联',
                                 buttons=[{'payload': '/button_part3_1_6_choose_3', 'title': '唔呣...', 'life': 1}, ])
        return []


class part3_1_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='即使你正在经历的仅仅是一个单独的负面事件，但是你还是会担心生活中的其他事情也会变得同样糟糕🙁',
                                 buttons=[{'payload': '/button_part3_1_7_choose_1', 'title': '哎……', 'life': 1},
                                          {'payload': '/button_part3_1_7_choose_1', 'title': '嗯嗯', 'life': 1}, ])
        return []


class part3_1_6_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_6_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我们在谈论的只是一个单纯的负面事件......但这种情况带来的压力可能会让人感到不知所措，以至于你担心生活中的其他一切都会变得同样糟糕',
                                 buttons=[{'payload': '/button_part3_1_7_choose_1', 'title': '明白了', 'life': 1},
                                          {'payload': '/button_part3_1_7_choose_1', 'title': '嗯嗯', 'life': 1}, ])
        return []


class part3_1_6_choose_3(Action):
    def name(self) -> Text:
        return "action_part3_1_6_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='即使你正在经历的仅仅是一个单独的负面事件，但是你还是会担心生活中的其他事情也会变得同样糟糕',
                                 buttons=[{'payload': '/button_part3_1_7_choose_2', 'title': '嗯嗯！', 'life': 1}, ])
        return []


class part3_1_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='好的，那么你的想法“' + text + '”是否包含任何类似于非黑即白的极端化想法呢？',
                                 buttons=[{'payload': '/button_part3_1_8_choose_1', 'title': '那是什么？', 'life': 1},
                                          {'payload': '/button_part3_1_8_choose_2', 'title': '是的', 'life': 1},
                                          {'payload': '/button_part3_1_8_choose_3', 'title': '不是这样', 'life': 1}, ])
        return []


class part3_1_7_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_7_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='所以你怎么看？你的这个想法“' + text + '”是否存在过度概括呢？',
                                 buttons=[{'payload': '/button_part3_1_7_choose_1', 'title': '是的', 'life': 1},
                                          {'payload': '/button_part3_1_7_choose_1', 'title': '不是这样', 'life': 1}, ])
        return []


class part3_1_8_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_8_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='非黑即白的极端化思维意味着陷入僵化的、全正面或全负面的思维方式')
        dispatcher.utter_message(text='它可能会导致我们错过某种情况下的重要细节。和过度概括一样，它经常涉及诸如“总是”或“从不”之类的词',
                                 buttons=[{'payload': '/button_part3_1_9_choose_1', 'title': '嗯嗯，我明白啦', 'life': 1}, ])
        return []


class part3_1_8_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_8_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='太棒啦，你识别出来啦！~~ 生活中的事情很少全是好的或全是坏的，以这种方式思考事情会使得自己感到不必要的困扰和痛苦，这是一个非常需要注意的地方！',
                                 buttons=[{'payload': '/button_part3_1_9_choose_2', 'title': '好~', 'life': 1}, ])
        return []


class part3_1_8_choose_3(Action):
    def name(self) -> Text:
        return "action_part3_1_8_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='太棒啦，让我们继续吧~',
                                 buttons=[{'payload': '/button_part3_1_9_choose_2', 'title': '好~', 'life': 1}, ])
        return []


class part3_1_9_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_9_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='生活中的事情很少都是好的或者都是坏的，以这种非黑即白的方式思考事情，会让我们感到不必要的困难和痛苦这是一个非常值得注意的问题',
                                 buttons=[{'payload': '/button_part3_1_10_choose_1', 'title': '好的', 'life': 1}, ])
        return []


class part3_1_9_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_9_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='你的想法“' + text + '”是否假设了其他人正在消极思考或做出消极反应？',
                                 buttons=[{'payload': '/button_part3_1_10_choose_2', 'title': '确实如此', 'life': 1},
                                          {'payload': '/button_part3_1_11_choose_2', 'title': '没有', 'life': 1}, ])
        return []


class part3_1_10_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_10_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='那么，你认为“' + text + '”这个想法包含任何极端化的想法吗?',
                                 buttons=[{'payload': '/button_part3_1_11_choose_1', 'title': '有哎……', 'life': 1},
                                          {'payload': '/button_part3_1_11_choose_1', 'title': '没有', 'life': 1}, ])
        return []


class part3_1_10_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_10_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='小可爱，你可太棒啦。')
        dispatcher.utter_message(text=' 这叫做读心术。当它在运行时，我们的反应就像有人在以特定的方式思考或反应一样——但事实上，我们哪儿能知道他们脑子里在想什么呢？',
                                 buttons=[{'payload': '/button_part3_1_11_choose_2', 'title': '太有道理了', 'life': 1}, ])
        return []


class part3_1_11_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_11_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='干得漂亮，我们继续来看',
                                 buttons=[{'payload': '/button_part3_1_9_choose_2', 'title': '好的', 'life': 1}, ])
        return []


class part3_1_11_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_11_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='你的想法“' + text + '”是不是把太多的责任都归结到你自己身上了?，即使那是一些你自己无法完全控制的事情?',
                                 buttons=[{'payload': '/button_part3_1_12_choose_1', 'title': '是的……', 'life': 1},
                                          {'payload': '/button_part3_1_12_choose_2', 'title': '没有，不是这样', 'life': 1}, ])
        return []


class part3_1_12_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_12_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我很理解你，对你无法控制的事情承担太多责任会让人感到非常艰难和痛苦的')
        dispatcher.utter_message(text='顺便说一下，这叫做“自责”，是一种“个人化”的表现。我们很容易直接产生这样想法，但其实事情不可能100%是你的错误',
                                 buttons=[{'payload': '/button_part3_1_13_choose_1', 'title': '明白了', 'life': 1}, ])
        return []


class part3_1_12_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_12_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='也许这个想法会把责任推到别人身上?',
                                 buttons=[{'payload': '/button_part3_1_13_choose_1', 'title': '没有', 'life': 1},
                                          {'payload': '/button_part3_1_13_choose_2', 'title': '是的', 'life': 1}, ])
        return []


class part3_1_13_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_13_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='好的，你认真地分析了你的想法“' + text + '”，你做得很棒呦~',
                                 buttons=[{'payload': '/button_part3_1_14_choose_1', 'title': '谢谢', 'life': 1}, ])
        return []


class part3_1_13_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_13_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='有时候，在很艰难的情形下，忽略自己在其中扮演的角色会更加容易，会少很多痛苦但没关系!这是人类天性的一部分',
                                 buttons=[{'payload': '/button_part3_1_14_choose_2', 'title': '我明白了', 'life': 1}, ])
        return []


class part3_1_14_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_14_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='现在，是这个过程中最重要的部分....',
                                 buttons=[{'payload': '/button_part3_1_15_choose_1', 'title': '是什么？', 'life': 1}, ])
        return []


class part3_1_14_choose_2(Action):
    def name(self) -> Text:
        return "action_part3_1_14_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='当你认为某件不好的事情是你的责任，甚至是比实际情况更多地与你有关时，我们称之为“个人化”，这个有出现在你的想法里吗?',
                                 buttons=[{'payload': '/button_part3_1_13_choose_1', 'title': '有哎……', 'life': 1},
                                          {'payload': '/button_part3_1_13_choose_1', 'title': '没有', 'life': 1}, ])
        return []


class part3_1_15_choose_1(Action):
    def name(self) -> Text:
        return "action_part3_1_15_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='去掉这些扭曲，重写你的想法“' + text + '”，让你的想法更加的客观和实际。怎么样？你能做到吗？', buttons=[
            {'payload': '/button_suggest_realistic', 'title': '我不知道怎么写……你能帮我吗？', 'life': 1},
            {'payload': '/button_rewrite_thought', 'title': '好的，我来试试看', 'life': 1},
        ])
        return []
        # dispatcher.utter_message(text='此功能开发中，敬请期待')
        # return [SessionStarted()]


class suggest_realistic(Action):
    def name(self) -> Text:
        return "action_suggest_realistic"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='当然可以啦~'),
        dispatcher.utter_message(text='我的建议是：要像与好朋友聊天一样与自己交谈。 试着变得更加富有同情心，更加贴合实际情况。'),
        dispatcher.utter_message(text='你不必努力让自己表现得很积极向上，只要贴近真实的情况就好', buttons=[
            {'payload': '/button_cognitive_distortion_photo', 'title': '能给我举个例子吗？', 'life': 1},
            {'payload': '/button_rewrite_thought', 'title': '我懂啦', 'life': 1},
        ])
        return []


class action_cognitive_distortion_photo(Action):
    def name(self) -> Text:
        return "action_cognitive_distortion_photo"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        url = 'https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/woebot/challenging_negativity.jpg'
        dispatcher.utter_message(text='是否有出现过度概括、非黑即白、读心术、责怪自己或者他人、个人化这些扭曲呢？')
        dispatcher.utter_message(text='图片中展示了几个例子，希望能对你有帮助~', image=url, buttons=[
            {'payload': '/button_rewrite_thought', 'title': '谢啦~', 'life': 1},
            {'payload': '/button_rewrite_thought', 'title': '哦哦~', 'life': 1},
        ])
        return []


class action_ask_rewrite_thought(Action):
    def name(self) -> Text:
        return "action_ask_rewrite_thought"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        text = current_thought(tracker)
        dispatcher.utter_message(text='现在，去掉这些扭曲，在下面的输入框中重写你的想法“' + text + '”吧~')
        return []


class action_how_did_you_do(Action):
    def name(self) -> Text:
        return "action_how_did_you_do"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute(
            "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
        x = cursor.fetchone()
        result_id = x[0]
        # cursor.execute(
        #     "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
        # x = cursor.fetchone()
        if tracker.get_slot('thought_3_change_1') == '1':
            rewrite = 'thought_one_modify'
        if tracker.get_slot('thought_3_change_1') == '2':
            rewrite = 'thought_two_modify'
        if tracker.get_slot('thought_3_change_1') == '3':
            rewrite = 'thought_three_modify'
        try:
            sql = "update `user_heart` set " + rewrite + "= '" + tracker.get_slot(
                'rewrite_thought') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='重写想法存储不成功')
            # return [SlotSet("rewrite_thought", None)]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text='你做得怎么样？', buttons=[
            {'payload': '/button_success', 'title': '我成功啦！~', 'life': 1},
            {'payload': '/button_tried', 'title': '我很努力哦~', 'life': 1},
            {'payload': '/button_rewrite_thought', 'title': '我想再试一次', 'life': 1},
            {'payload': '/button_cant_do_it', 'title': '不太成功……', 'life': 1},
            {'payload': '/button_how_rewrite', 'title': '我要怎么重写啊？', 'life': 1},
        ])
        return [SlotSet("rewrite_thought", None)]


# ------------------
class action_success(Action):
    def name(self) -> Text:
        return "action_success"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        try:
            i = random.randint(1, 3)
            url = 'https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/highfive/highfive_' + str(
                i) + '.jpg'
            dispatcher.utter_message(text='你太棒啦！！', image=url, buttons=[
                {'payload': '/button_success_yes', 'title': '谢啦~', 'life': 1},
                {'payload': '/button_success_yes', 'title': '嘿嘿嘿，我就是这么厉害！', 'life': 1},
            ])
        except:
            dispatcher.utter_message(text='你太棒啦！！🌻', buttons=[
                {'payload': '/button_success_yes', 'title': '谢啦~', 'life': 1},
                {'payload': '/button_success_yes', 'title': '嘿嘿嘿，我就是这么厉害！', 'life': 1},
            ])
        return []


class action_tried(Action):
    def name(self) -> Text:
        return "action_tried"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        try:
            i = random.randint(1, 3)
            url = 'https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/highfive/highfive_' + str(
                i) + '.jpg'
            dispatcher.utter_message(text='努力是最难的部分了'),
            dispatcher.utter_message(text='你做得非常非常好啦，给你一朵小花花~ 🌻', image=url, buttons=[
                {'payload': '/button_success_yes', 'title': '谢啦~', 'life': 1},
            ])
        except:
            dispatcher.utter_message(text='努力是最难的部分了'),
            dispatcher.utter_message(text='你做得非常非常好啦，给你一朵小花花~ 🌻', buttons=[
                {'payload': '/button_success_yes', 'title': '谢啦~', 'life': 1},
            ])
        return []


class action_cant_do_it(Action):
    def name(self) -> Text:
        return "action_cant_do_it"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是的，这可能很难……但是通过练习，你会掌握窍门的!'),
        dispatcher.utter_message(text='让我举一个我认为可能有用的例子吧', buttons=[
            {'payload': '/button_success_yes', 'title': '不用了，谢谢', 'life': 1},
            {'payload': '/button_cant_do_it_yes', 'title': '好', 'life': 1},
        ])
        return []


class action_example_1(Action):
    def name(self) -> Text:
        return "action_example_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='假设我的想法是“我不应该那样说的，我总是让自己像个傻子一样”', buttons=[
            {'payload': '/button_example_1_yes', 'title': '嗯嗯', 'life': 1},
        ])
        return []


class action_example_2(Action):
    def name(self) -> Text:
        return "action_example_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='在这个想法中包括了：加标签、“应该”类型的陈述和过度概括的表达。'),
        dispatcher.utter_message(text='我会试着找出那些让我的想法扭曲的词语——比如“傻瓜”的标签，或者“总是”和“应该”的词语。'),
        dispatcher.utter_message(text='然后我会替换这些词语或者重新思考怎么描述，让我的想法更基于现实也更加地平衡⚖️', buttons=[
            {'payload': '/button_example_2_yes', 'title': '哦~', 'life': 1},
        ])
        return []


class action_example_3(Action):
    def name(self) -> Text:
        return "action_example_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='所以我的重写可能是这样的:'),
        dispatcher.utter_message(text='我当时可以换一种说法的，但是在聊天时说出尴尬的话并不能代表我傻呀'),
        dispatcher.utter_message(text='现在，你想要一次重写的剧本机会吗?', buttons=[
            {'payload': '/button_rewrite_thought', 'title': '嗯嗯，我想重写一次', 'life': 1},
            {'payload': '/button_success_yes', 'title': '不了，谢谢', 'life': 1},
        ])
        return []


# class action_part4_1_1_choose_1(Action):
#     def name(self) -> Text:
#         return "action_part4_1_1_choose_1"
#     async def run(
#             self,
#             dispatcher: CollectingDispatcher,
#             tracker: Tracker,
#             domain: Dict[Text, Any],
#     ) -> List[Dict[Text, Any]]:
#         conversation_rounds(tracker)
#         dispatcher.utter_message(text='功能未完成，敬请期待'),
#         return []

# ----------------------------------------------------part 4----------------------------------------------------------------
class part4_1_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='好吧，你现在感觉如何?', buttons=[
            {'payload': '/button_part4_1_2_choose_1', 'title': '感觉没啥变化', 'life': 1},
            {'payload': '/button_part4_1_2_choose_2', 'title': '变好一些了……', 'life': 1},
            {'payload': '/button_part4_1_2_choose_3', 'title': '更糟糕了', 'life': 1}, ])
        return []


class part4_1_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你知道，不让自己感觉更糟本身就是一种胜利。使船浮起来并不总是容易的')
        dispatcher.utter_message(text='你今天能够保持稳定已经非常厉害啦', buttons=[
            {'payload': '/button_part4_1_3_choose_1', 'title': '谢啦', 'life': 1}, ])
        return []


class part4_1_2_choose_2(Action):
    def name(self) -> Text:
        return "action_part4_1_2_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='哇！你太棒啦', buttons=[
            {'payload': '/button_part4_1_3_choose_2', 'title': '谢啦~', 'life': 1}, ])
        return []


class part4_1_2_choose_3(Action):
    def name(self) -> Text:
        return "action_part4_1_2_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我也为你感到难过了。')
        dispatcher.utter_message(text='我可以给你分享一些导致你觉得情况更加糟糕的原因吗？', buttons=[
            {'payload': '/button_part4_1_3_choose_3', 'title': '好的', 'life': 1},
            {'payload': '/button_part4_1_3_choose_4', 'title': '不用了', 'life': 1}, ])
        return []


class part4_1_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='在我们签退之前，恭喜你在第一天完整的学习了一个工具。')
        dispatcher.utter_message(text='好棒！🎉', buttons=[
            {'payload': '/button_part4_1_4_choose_1', 'title': '谢啦~', 'life': 1},
            {'payload': '/button_part4_1_4_choose_1', 'title': '嘿嘿', 'life': 1}, ])
        return []


class part4_1_3_choose_2(Action):
    def name(self) -> Text:
        return "action_part4_1_3_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='点击下方的"选择功能"就可以随时练习了呦')
        dispatcher.utter_message(text='顺便一提,当前的这个工具称作"挑战认知"', buttons=[
            {'payload': '/button_part4_1_4_choose_1', 'title': '我知道啦', 'life': 1}, ])
        return []


class part4_1_3_choose_3(Action):
    def name(self) -> Text:
        return "action_part4_1_3_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='首先，你能够从你的想法中找到任何认知扭曲的部分吗？', buttons=[
            {'payload': '/button_part4_1_4_choose_2', 'title': '能', 'life': 1},
            {'payload': '/button_part4_1_4_choose_3', 'title': '其实……没有找到……', 'life': 1}, ])
        return []


class part4_1_3_choose_4(Action):
    def name(self) -> Text:
        return "action_part4_1_3_choose_4"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='在你登出之前，我想要夸奖你有很努力地完成了一次尝试呢！', buttons=[
            {'payload': '/button_part4_1_3_choose_2', 'title': '谢谢小E陪我一起进步~', 'life': 1}, ])
        return []


class part4_1_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='在我们结束之前，再花费两分钟的时间，讨论几个与今天所学内容相关的问题吧！')
        dispatcher.utter_message(text='回顾今天的学习内容，可以帮助你更好地掌握重构消极思想的技能哦~', buttons=[
            {'payload': '/button_part4_1_5_choose_1', 'title': '好的', 'life': 1},
            {'payload': '/button_part4_1_5_choose_2', 'title': '现在没有时间', 'life': 1}, ])
        return []


class part4_1_4_choose_2(Action):
    def name(self) -> Text:
        return "action_part4_1_4_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你有多相信你重新写的想法呢？', buttons=[
            {'payload': '/button_part4_1_6_choose_3', 'title': '百分之百相信', 'life': 1},
            {'payload': '/button_part4_1_5_choose_3', 'title': '相信一部分吧……', 'life': 1}, ])
        return []


class part4_1_4_choose_3(Action):
    def name(self) -> Text:
        return "action_part4_1_4_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='那我明白啦！怪不得其他的过程都没有起到作用')
        dispatcher.utter_message(text='我还可以给你介绍其他的认知扭曲，只是不想一次给你太多的压力', buttons=[
            {'payload': '/button_part4_1_4_choose_2', 'title': '我知道啦', 'life': 1}, ])
        return []


class part4_1_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='在和我一起学习了这个工具后，你是否觉得能够识别出想法中出现扭曲的部分？', buttons=[
            {'payload': '/button_part4_1_6_choose_1_1', 'title': '可以', 'life': 1},
            {'payload': '/button_part4_1_6_choose_1_2', 'title': '应该可以', 'life': 1},
            {'payload': '/button_part4_1_6_choose_1_3', 'title': '也许？', 'life': 1},
            {'payload': '/button_part4_1_6_choose_1_4', 'title': '不太行', 'life': 1},
            {'payload': '/button_part4_1_6_choose_1_5', 'title': '不可以', 'life': 1},
            {'payload': '/button_part4_1_6_choose_1_6', 'title': '我也不确定……', 'life': 1}, ])
        return []


class part4_1_5_choose_2(Action):
    def name(self) -> Text:
        return "action_part4_1_5_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conversation_rounds(tracker)
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='好吧~你今天很努力很棒哦！')
        dispatcher.utter_message(text='你已完成当天的实验流程')
        dispatcher.utter_message(text='暂时拜拜啦~', buttons=[
            {'payload': '/greet', 'title': '拜拜ヾ(•ω•`)o', 'life': 1}, ])
        return []


class part4_1_5_choose_3(Action):
    def name(self) -> Text:
        return "action_part4_1_5_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='啊……好的~ 只有你完全相信你重新写的想法，才能够感到更好些呢~', buttons=[
            {'payload': '/button_part4_1_6_choose_3', 'title': '我知道了', 'life': 1}, ])
        return []


class part4_1_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        if (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_6_choose_1_1'):
            score = '可以'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_6_choose_1_2'):
            score = '应该可以'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_6_choose_1_3'):
            score = '也许'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_6_choose_1_4'):
            score = '不太行'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_6_choose_1_5'):
            score = '不可以'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_6_choose_1_6'):
            score = '我也不确定……'
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute(
            "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
        x = cursor.fetchone()
        result_id = x[0]
        userid = tracker.current_state()['sender_id']
        sql = "update `user_heart` set able_to_identify_thought= '" + score + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='你是否能更好的识别出思维中的一个或多个扭曲?', buttons=[
            {'payload': '/button_part4_1_7_choose_1_1', 'title': '可以', 'life': 1},
            {'payload': '/button_part4_1_7_choose_1_2', 'title': '应该可以', 'life': 1},
            {'payload': '/button_part4_1_7_choose_1_3', 'title': '也许？', 'life': 1},
            {'payload': '/button_part4_1_7_choose_1_4', 'title': '不太行', 'life': 1},
            {'payload': '/button_part4_1_7_choose_1_5', 'title': '不可以', 'life': 1},
            {'payload': '/button_part4_1_7_choose_1_6', 'title': '我也不确定……', 'life': 1}, ])
        return []


class part4_1_6_choose_3(Action):
    def name(self) -> Text:
        return "action_part4_1_6_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='还有一些别的原因：如果你的想法中，只包括一个需要挑战的因素，那么就会比较容易发现其中的问题', buttons=[
            {'payload': '/button_part4_1_7_choose_2', 'title': '哦哦~', 'life': 1}, ])
        return []


class part4_1_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conversation_rounds(tracker)
        if (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_7_choose_1_1'):
            score = '可以'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_7_choose_1_2'):
            score = '应该可以'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_7_choose_1_3'):
            score = '也许'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_7_choose_1_4'):
            score = '不太行'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_7_choose_1_5'):
            score = '不可以'
        elif (tracker.current_state()['events'][-2]['parse_data']['intent']['name'] == 'button_part4_1_7_choose_1_6'):
            score = '我也不确定……'
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute(
            "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
        x = cursor.fetchone()
        result_id = x[0]
        userid = tracker.current_state()['sender_id']
        sql = "update `user_heart` set able_to_identify_distortion= '" + score + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='你是否觉得更有能力改写一个扭曲的思想，让想法变得更加平衡或公平？', buttons=[
            {'payload': '/button_into_improvement_suggestions_1', 'title': '可以', 'life': 1},
            {'payload': '/button_into_improvement_suggestions_2', 'title': '应该可以', 'life': 1},
            {'payload': '/button_into_improvement_suggestions_3', 'title': '也许？', 'life': 1},
            {'payload': '/button_into_improvement_suggestions_4', 'title': '不太行', 'life': 1},
            {'payload': '/button_into_improvement_suggestions_5', 'title': '不可以', 'life': 1},
            {'payload': '/button_into_improvement_suggestions_6', 'title': '我也不确定……', 'life': 1}, ])
        return []


class part4_1_7_choose_2(Action):
    def name(self) -> Text:
        return "action_part4_1_7_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我们很难去挑战你说的某种感觉比如：”我孤身一人的时候感觉很糟糕“像这样描述一个感受，很难在其中找到扭曲的认知。', buttons=[
            {'payload': '/button_part4_1_8_choose_1', 'title': '我明白了', 'life': 1}, ])
        return []


class part4_1_8_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_8_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='小E现在还只是一个可怜、弱小又无助的机器人儿，我没法评论你写的具体内容，我只能提供给你一个改变的思路如果你想要得到更多的帮助和指导，可以去找一个心理咨询师哦~',
                                 image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/pitful.png',
                                 buttons=[
                                     {'payload': '/button_part4_1_9_choose_1', 'title': '好的', 'life': 1}, ])
        return []


class part4_1_9_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_9_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='这些理由可以解释你现在面临的情况吗？', buttons=[
            {'payload': '/button_part4_1_10_choose_1', 'title': '我写的想法里包括太多方面了', 'life': 1},
            {'payload': '/button_part4_1_10_choose_2', 'title': '我写的内容是关于感觉的', 'life': 1},
            {'payload': '/button_part4_1_10_choose_3', 'title': '我更想要跟人对话', 'life': 1},
            {'payload': '/button_part4_1_10_choose_4', 'title': '这些理由中不包含我的情况', 'life': 1}, ])
        return []


class part4_1_10_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_10_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你已经进步很大啦！')
        dispatcher.utter_message(text='下次要记得把长的想法切分成几条各自独立的想法哦~', buttons=[
            {'payload': '/button_part4_1_11_choose_1', 'title': '好的', 'life': 1}, ])
        return []


class part4_1_10_choose_2(Action):
    def name(self) -> Text:
        return "action_part4_1_10_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='哎呀~那些感受有时候真的很难挑战的。')
        dispatcher.utter_message(text='你已经很棒啦~下次我们再一起努力解决一个想法吧~', buttons=[
            {'payload': '/button_part4_1_11_choose_1', 'title': '好~', 'life': 1}, ])
        return []


class part4_1_10_choose_3(Action):
    def name(self) -> Text:
        return "action_part4_1_10_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我理解哒')
        dispatcher.utter_message(text='如你所见，我并不能取代人与人之间的人际交往，我只是一个帮助人类练习CBT认知行为干预的一种途径。')
        dispatcher.utter_message(text='但是，这是你走出坏情绪的重要一步哦~希望你能找到可以寻求帮助的专业人士。', buttons=[
            {'payload': '/button_part4_1_11_choose_1', 'title': '好的', 'life': 1}, ])
        return []


class part4_1_10_choose_4(Action):
    def name(self) -> Text:
        return "action_part4_1_10_choose_4"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='(⊙o⊙)？我知道啦~我们会继续努力优化这个过程哒～', buttons=[
            {'payload': '/button_part4_1_11_choose_1', 'title': '谢谢', 'life': 1}, ])
        return []


class part4_1_11_choose_1(Action):
    def name(self) -> Text:
        return "action_part4_1_11_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='在你登出之前，我忍不住想夸奖你呢~你很好地完成了一次尝试！')
        dispatcher.utter_message(text='好棒呀！🎉', buttons=[
            {'payload': '/button_part4_1_3_choose_2', 'title': '嘿嘿，谢谢~~', 'life': 1}, ])
        return []


class action_ask_improvement_suggestions(Action):
    def name(self) -> Text:
        return "action_ask_improvement_suggestions"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        if (tracker.current_state()['events'][-5]['parse_data']['intent'][
            'name'] == 'button_into_improvement_suggestions_1'):
            score = '可以'
        elif (tracker.current_state()['events'][-5]['parse_data']['intent'][
                  'name'] == 'button_into_improvement_suggestions_2'):
            score = '应该可以'
        elif (tracker.current_state()['events'][-5]['parse_data']['intent'][
                  'name'] == 'button_into_improvement_suggestions_3'):
            score = '也许'
        elif (tracker.current_state()['events'][-5]['parse_data']['intent'][
                  'name'] == 'button_into_improvement_suggestions_4'):
            score = '不太行'
        elif (tracker.current_state()['events'][-5]['parse_data']['intent'][
                  'name'] == 'button_into_improvement_suggestions_5'):
            score = '不可以'
        elif (tracker.current_state()['events'][-5]['parse_data']['intent'][
                  'name'] == 'button_into_improvement_suggestions_6'):
            score = '我也不确定……'
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute(
            "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
        x = cursor.fetchone()
        result_id = x[0]
        userid = tracker.current_state()['sender_id']
        sql = "update `user_heart` set able_to_rewrite_distortion= '" + score + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='小E想要变得更加优秀')
        dispatcher.utter_message(text='给我一些建议，让我对你更有帮助吧~')
        dispatcher.utter_message(text='请不要点击任何选项哦')
        return []


class action_part4_thank_1(Action):
    def name(self) -> Text:
        return "action_part4_thank_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        cursor.execute(
            "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
        x = cursor.fetchone()
        result_id = x[0]
        userid = tracker.current_state()['sender_id']
        sql = "update `user_heart` set improvement_suggestion= '" + tracker.get_slot(
            'improvement_suggestions') + "' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
        common.connectmysql(sql)
        conversation_rounds(tracker)
        dispatcher.utter_message(text='非常感谢你回答小E的这些问题!')
        dispatcher.utter_message(text='我真的很感谢你抽出时间来帮助我把整个流程的体验变得更好', buttons=[
            {'payload': '/button_part4_thank_2', 'title': '不客气', 'life': 1}, ])
        return []


class action_part4_thank_2(Action):
    def name(self) -> Text:
        return "action_part4_thank_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conversation_rounds(tracker)
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='今天你很棒哦，非常努力啦')
        dispatcher.utter_message(text='你已完成当天的实验流程')
        dispatcher.utter_message(text='让自己好好的休息一下吧!再见~', buttons=[
            {'payload': '/greet', 'title': '再见', 'life': 1}, ])
        return []


class action_show_tool(Action):
    def name(self) -> Text:
        return "action_show_tool"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        a = [
            {'payload': '/into_grateful_thing_input_1', 'title': '感恩日记', 'life': 1},
            {'payload': '/button_part2_1_choose_1', 'title': '挑战认知', 'life': 1}]
        b = [
            {'payload': '/button_part5_1_1_choose_1', 'title': '提升自尊', 'life': 1},
            {'payload': '/button_part13_1_1_choose_1', 'title': '学会放松', 'life': 1},
            {'payload': '/button_build_power', 'title': '能量清单', 'life': 1},
            {'payload': '/button_part11_1_1_choose_1', 'title': '美丽世界', 'life': 1},
            {'payload': '/button_part8_1_1_choose_1', 'title': '你还好吗', 'life': 1},
            {'payload': '/button_part9_1_1_choose_1', 'title': '远离孤独', 'life': 1}]
        userid = tracker.current_state()['sender_id']
        user_type = None
        user_days = None
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute("Select * from `user_info` where `id` = '" + userid + "'")
            t = cursor.fetchone()
            user_type = t[24]
            user_days = t[27]
        except:
            dispatcher.utter_message('机器人错误 错误码0x001A')
        finally:
            cursor.close()
            conn.close()
        if user_type == 2 or user_type == 3:
            dispatcher.utter_message(text='您不能使用该功能', buttons=[{'payload': '/greet', 'title': '返回首页', 'life': 1}])
            return []
        if user_type == 0 or user_days >= 7:
            dispatcher.utter_message(text='请选择试验工具', buttons=a + b, json_message={"module_type": 2})
        else:
            if user_days == 1 or user_days == -1:
                dispatcher.utter_message(text='请选择试验工具', buttons=a, json_message={"module_type": 2})
                return []
            else:
                a = a + b[:(user_days - 1)]
                dispatcher.utter_message(text='请选择试验工具', buttons=a, json_message={"module_type": 2})
        return []
